package com.service.impl;

import com.dao.UsersDao;
import com.dao.impl.UserDaoImpl;
import com.pojo.PageBean;
import com.pojo.Users;
import com.service.UsersService;

import java.util.List;

public class UsersServiceImpl implements UsersService {
    private UsersDao dao = new UserDaoImpl();

    //查询所有用户
    @Override
    public PageBean<Users> findAllUsers(int limit,int current) {
        //查询行数
        int count = dao.selectCount();
        //获取数据
        List<Users> list = dao.findAllUsers((current-1)*limit, limit);
        PageBean<Users> pageBean = new PageBean<>();
        pageBean.setData(list);
        pageBean.setCurrent(current);
        pageBean.setTotal(count);
        return pageBean;
    }

    //登录
    @Override
    public Users login(Users users) {
        return dao.login(users);
    }

    //删除用户
    @Override
    public boolean deleteUser(String id) {
        return dao.deleteUser(id)>0;
    }

    //新增用户
    @Override
    public boolean addUser(Users users) {
        return dao.addUser(users)>0;
    }

    //根据ID查询用户
    @Override
    public Users findUsersByID(String id) {
        return dao.findUsersByID(id);
    }

    //修改用户
    @Override
    public boolean updateUser(Users users) {
        return dao.updateUser(users)>0;
    }

    //查询用户名
    @Override
    public boolean findUsername(String username) {
        return dao.findUsername(username).size()>0;
    }
}
